# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Test loading a NaCl-enabled Chrome Extension.

Import('env')

# Disable Chrome extention tests until issue with Windows is fixed
# and test is moved into Chrome repo.
# BUG http://code.google.com/p/chromium/issues/detail?id=105481
Return()

# BUG(adonovan): test is breaking on ARM.  Disable in haste...
if env.Bit('build_arm'):
  Return()
env.Replace(TEST_DIR='${SOURCE_ROOT}/ppapi/native_client/tests/' +
                     'ppapi_test_example')

nexe = env.ProgramNameForNmf('ppapi_test_example') + '${PROGSUFFIX}'

# Note: this test uses the nexe, manifest.json, background.html and
# test_bridge.js, but these files are loaded from the disk as part of the
# installed Chrome extension and not loaded through the tester's web server.
# These files need their own install command.
dest_copy = env.Replicate('$STAGING_DIR/chrome_extension',
                          [env.File('$STAGING_DIR/%s' % nexe),
                           'background.html',
                           'manifest.json',
                           'test_bridge.js'])
dest_copy.append(env.CopyLibsForExtension(
    '$STAGING_DIR/chrome_extension',
    '$STAGING_DIR/ppapi_test_example.nmf'))

node = env.PPAPIBrowserTester(
    'chrome_extension_test.out',
    url='chrome_extension_test.html',
    nmfs=['${TEST_DIR}/ppapi_test_example.nmf'],
    extensions=[env.Dir('$STAGING_DIR/chrome_extension')],
    files=[env.File('chrome_extension_test.html')]
    )
env.Depends(node, dest_copy)
env.Alias('all_programs', dest_copy)

# TODO(eugenis): enable on Valgrind when it learns to autodetect the nexe name
env.AddNodeToTestSuite(
    node,
    ['chrome_browser_tests'],
    'run_chrome_extension_test',
    is_broken=env.PPAPIBrowserTesterIsBroken() or
               env.Bit('running_on_valgrind'))
